﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using compshop.Infrastructure.CompShopDataService;
using compshop.Modules.ListOfGoodsInWaybill.Presenter;

namespace compshop.Modules.ListOfGoodsInWaybill.View
{
    /// <summary>
    /// Логика взаимодействия для GoodsListInWaybillView.xaml
    /// </summary>
    public partial class GoodsListInWaybillView : UserControl, IViewGoodsListInWaybill
    {
        
        public GoodsListInWaybillView()
        {
            InitializeComponent();
           
        }

        public GoodsListInWaybillView(GoodsListInWaybillPresenter presenter)
            : this()
        {
            Presenter = presenter;
            Presenter.View = this;
            btnSave.Click += new RoutedEventHandler(btnSave_Click);
        }
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Waybill changes = new Waybill();
            changes.ReceiverID = (int)cbReceiver.SelectedValue;
            changes.SenderID = (int)cbSender.SelectedValue;
            DateTime temp;
           bool rez= DateTime.TryParse(tbSendingDate.Text,out temp);
           if (rez)
               changes.SendingDate = temp;
           else MessageBox.Show("Неверно введена дата отправки!");
           rez = DateTime.TryParse(tbReceivingDate.Text, out temp);
           if (rez)
               changes.ReceivingDate = temp;
           else if (tbReceivingDate.Text!="") MessageBox.Show("Неверно введена дата прибытия!");
             
           Presenter.save(changes);
        }

       
        public GoodsListInWaybillPresenter Presenter
        {
            get { return DataContext as GoodsListInWaybillPresenter; }
            set { DataContext = value; }
        }

       public void refresh(GoodsListInWaybillPresenter presenter )
       {
           Presenter = null;
           Presenter = presenter;
       }
       
    }
}
